package com.pi.base.common;

import java.io.Serializable;

public class BaseResult implements Serializable {
	private int status;
	private String msg;
	private Object data;
	
	
	public static final int STATUS_ERROR = 0;
	public static final int STATUS_OK = 1;
	public static final int STATUS_NOLOGIN = -1;
	public static final int STATUS_FAILD = 2;
	
	public BaseResult(){
	}
	

	public BaseResult(int status){
		this.status = status;
	}
	
	public BaseResult(int status,String msg){
		this.status = status;
		this.msg = msg;
	}
	
	public BaseResult(int status, String msg, Object data) {
		super();
		this.status = status;
		this.msg = msg;
		this.data = data;
		
	}
	
	public static BaseResult faild(){
		return  new BaseResult(STATUS_FAILD,"失败");
	}
	public static BaseResult faild(String msg){
		return  new BaseResult(STATUS_FAILD,msg);
	}

	public static BaseResult newErrorResult(){
		return  new BaseResult(STATUS_ERROR,"操作失败");
	}
	
	public static BaseResult newErrorResult(String err){
		return  new BaseResult(STATUS_ERROR,err);
	}
	 public static BaseResult newErrorResult(String err,Object data){
	    return  new BaseResult(STATUS_ERROR,err,data);
	  }
	
	public static BaseResult newErrorResult(Exception e){
		return  new BaseResult(STATUS_ERROR,e.getMessage());
	}
	/**
	 * @description 根据泛型类得出异常消息的返回结果
	 * @param e
	 * @param filterClass
	 * @param message
	 * @return
	 */
  public static <T>BaseResult newErrorResult(Exception e, Class<T> filterClass, String message){
    if(e.getClass() == filterClass){
      return  new BaseResult(STATUS_ERROR,e.getMessage());
    }else{      
      return  new BaseResult(STATUS_ERROR,message);
    }
  }	
	
	public static BaseResult newSuccessResult(){
		return  new BaseResult(STATUS_OK,"操作成功");
	}
	
	public static BaseResult newSuccessResult(String msg){
		return  new BaseResult(STATUS_OK,msg);
	}
	
	public static BaseResult newSuccessResult(String msg,Object data){
		return  new BaseResult(STATUS_OK,msg,data);
	}
	
	public  boolean equalSuccess(){
		return getStatus() == STATUS_OK;
	}
	
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}


	
}
